﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class FND_BANK : RibbonForm
    {
        public FND_BANK()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        
        public string SelectedBankCode { get; set; }
        public string SelectedBankName { get; set; }

        private void FND_BANK_Load(object sender, EventArgs e)
        {
            cboSearch.SelectedIndex = 0;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtSearch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            BankManager oManager = new BankManager();

            oManager.ConnectionString = this.ConnectionString;

            oManager.Open();

            if (cboSearch.SelectedIndex == 0)
            {
                DataTable tbl = new DataTable();

                tbl = oManager.BrowseBanksByCode(txtSearch.Text);

                gridControl1.DataSource = tbl;
                gridControl1.Refresh();
            }

            if (cboSearch.SelectedIndex == 1)
            {
                DataTable tbl = new DataTable();

                tbl = oManager.BrowseBanksByName(txtSearch.Text);

                gridControl1.DataSource = tbl;
                gridControl1.Refresh();
            }

            oManager.Close();
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            int iFocusRowIndex = gridView1.FocusedRowHandle;

            this.SelectedBankCode = gridView1.GetRowCellValue(iFocusRowIndex, gridView1.Columns["BankCode"]).ToString();
            this.SelectedBankName = gridView1.GetRowCellValue(iFocusRowIndex, gridView1.Columns["BankName"]).ToString();


            this.Close();
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnChoose_Click(sender, e);
            }
        }


    }
}
